import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../../config/color_config.dart';
import '../../config/string_config.dart';
import '../../config/text_style_config.dart';
import '../../config/image_config.dart';
import '../../utils/screen_util.dart';

class RoomItem extends StatelessWidget {
  final String roomName;
  final int machineCount;
  final int kioskCount;
  final int modemCount;
  final VoidCallback? onInstallReader;

  const RoomItem({
    Key? key,
    required this.roomName,
    required this.machineCount,
    required this.kioskCount,
    required this.modemCount,
    this.onInstallReader,
  }) : super(key: key);

  Widget _buildCountItem(String icon, int count, String label) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              width: 25,
              height: 25,
              decoration: const BoxDecoration(
                color: ColorConfig.iconBackground,
                shape: BoxShape.circle,
              ),
              child: Center(
                child: SvgPicture.asset(
                  icon,
                  width: 16,
                  height: 16,
                  colorFilter: const ColorFilter.mode(
                    ColorConfig.white,
                    BlendMode.srcIn,
                  ),
                ),
              ),
            ),
            const SizedBox(width: 5),
            Text(
              count.toString(),
              style: TextStyleConfig.itemCount,
            ),
          ],
        ),
        const SizedBox(height: 5),
        Text(
          label,
          style: TextStyleConfig.itemLabel,
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Container(
          padding: const EdgeInsets.all(16),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(7),
            boxShadow: const [
              BoxShadow(
                color: Color(0x40000000),
                blurRadius: 7,
                offset: Offset(0, 2),
              ),
            ],
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    roomName,
                    style: TextStyleConfig.roomTitle,
                  ),
                  const SizedBox(height: 10),
                  Row(
                    children: [
                      _buildCountItem(
                        ImageConfig.settingsIcon,
                        machineCount,
                        StringConfig.machines,
                      ),
                      const SizedBox(width: 15),
                      _buildCountItem(
                        ImageConfig.kioskVector1,
                        kioskCount,
                        StringConfig.kiosks,
                      ),
                      const SizedBox(width: 15),
                      _buildCountItem(
                        ImageConfig.modemVector1,
                        modemCount,
                        StringConfig.modems,
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ),
        Positioned(
          top: ScreenUtil.setHeight(20),
          right: ScreenUtil.setWidth(10),
          child: Material(
            color: ColorConfig.primary,
            borderRadius: BorderRadius.circular(5),
            child: InkWell(
              onTap: onInstallReader,
              borderRadius: BorderRadius.circular(5),
              child: Container(
                height: 24,
                padding:
                const EdgeInsets.symmetric(horizontal: 5, vertical: 3),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    SvgPicture.asset(
                      ImageConfig.toolIcon,
                      width: 16,
                      height: 16,
                      colorFilter: const ColorFilter.mode(
                        ColorConfig.white,
                        BlendMode.srcIn,
                      ),
                    ),
                    const SizedBox(width: 5),
                    Text(
                      StringConfig.installReader,
                      style: TextStyleConfig.buttonText,
                    ),
                  ],
                ),
              ),
            ),
          ),
        )
        ],
    );
  }
}
